package com.javachmapi.ftp.config;


import com.google.common.collect.Lists;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.async.DeferredResult;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger.web.UiConfiguration;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

/**
 *  通过java代码配置Swagger
 *  @Configuration表示是配置文件
 *  @EnableSwagger2开启这个配置
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    UiConfiguration uiConfig() {
        return new UiConfiguration(null, // url
                "list", // docExpansion => none | list
                "alpha", // apiSorter => alpha
                "schema", // defaultModelRendering => schema
                UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS, false, // enableJsonEditor => true | false
                true, null);
    }

    /**
     * 定义api组，
     */
    @Bean
    public Docket adminApi() {
        List<Parameter> parameterList = Lists.newArrayList();
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("FTP操作开发文档")
                .enable(true)
                .genericModelSubstitutes(DeferredResult.class)
                .useDefaultResponseMessages(false)
                .globalOperationParameters(parameterList)
                .forCodeGeneration(true)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.javachmapi.ftp.controller"))
                .paths(PathSelectors.any())
                .build()
                .directModelSubstitute(boolean.class, Boolean.class)
                .apiInfo(apiInfo());
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("FTP操作开发文档")//大标题
                .description("上传等服务")//详细描述
                .version("1.0")//版本
                .termsOfServiceUrl("ftp://106.14.117.234:21")
                .contact(new Contact("宋利军", "https://www.javachmapi.com", "javachmapi@qq.com"))
                .build();
    }
}
